#ifndef pid_h
#define pid_h 

// PID参数
float pid_kp = 2.0;
float pid_ki = 0.5;
float pid_kd = 1.0;

// PID状态变量
float pid_integral = 0;
float pid_last_error = 0;

// PID控制函数
// target: 目标温度
// current: 当前温度
// dt: 时间间隔（秒）
float pid_control(float target, float current, float dt) {
    float error = target - current;
    pid_integral += error * dt;
    float derivative = (error - pid_last_error) / dt;
    float output = pid_kp * error + pid_ki * pid_integral + pid_kd * derivative;
    pid_last_error = error;
    return output; // 输出值可用于调节加热/冷却设备
}

#endif